var wh = $(window).height();
$(function(){
    init();
});
function init(){
    e();
    s();
}

function e(){

}

// swiper初始化
function s(){
    // 首页banner
    homeBanner = new Swiper(".homeBanner",{
        slidesPerView: 1,
        autoplay: 3000,
        loop: true,
        pagination : '.homeBanner-pagination',
        paginationClickable :true
    });
    $(".homeBanner").hover(function () {
        homeBanner.stopAutoplay();
    }, function () {
        homeBanner.startAutoplay();
    });
}
$(".form-btn").click(function(){
    var name = $(".input-name").val(),
        phone = $(".input-phone").val(),
        grade = $("select[name='grade']").val(),
        subject = $("select[name='subject']").val(),
        remark = $(".input-remark").val();
    if(!name){
        alert("姓名不能为空");
        return false;
    }
    if(!phone){
        alert("手机号码不能为空");
        return false;
    }
    if(!(/^1[34578]\d{9}$/.test(phone))){
        alert("手机号码有误");
        return false;
    }
    if(!grade){
        alert("年级不能为空");
        return false;
    }
    if(!subject){
        alert("科目不能为空");
        return false;
    }
    if(!remark){
        alert("备注不能为空");
        return false;
    }
    if(name&&phone&&grade&&subject&&(/^1[34578]\d{9}$/.test(phone))){
        $(".form-btn").attr("disabled", true);
        $('.form-btn').text("正在提交......").css("cssText","background-color: rgb(189, 189, 189);box-shadow: 0px 0px 0px transparent;");
    }
    var post = {"name":name,"phone":phone,"grade":grade,"subject":subject,"remarke_type":2,'remark':remark};
    $.ajax({
        type: "POST",dataType:"json", url: "index.php?s=mobile", data: post,
        success: function(data) {
            if (data.status) {
                // dr_tips('报名成功....', 3, 1);
                dr_tips(data.code);
                //$(".form-btn").attr("disabled", true);


                $(".success-poup-box").fadeIn("slow");
                $(".success-poup-box").delay(2000).fadeOut("slow");
                //window.location.href = './index.php?s=mobile&c=home&m=sixone';
                setTimeout('window.location.href="./index.php?s=mobile&c=home&m=startSchool"',2000);
                // setTimeout('window.location.href="'+data.backurl+'"', <?php echo $_GET['debug'] ? 999999: 2000;?>);
            } else {
                dr_tips(data.code);
            }
        },
        error: function(HttpRequest, ajaxOptions, thrownError) {
            alert(HttpRequest.responseText);
        }
    });
});



$("body>.pc-activity-form .close-form").click(function(){
    $("body>.part2 .close-form,body>.part2 .pc-activity-form,body>.part2").fadeOut();
});
$(".btn-more").click(function(){
    $("body>.part2 .close-form,body>.part2 .pc-activity-form,body>.part2").fadeIn();
});
$('.btn-more').click(function(e) {
    var offset = $(this).offset();
    var y = e.clientY - offset.top;
    var height = (y*(-1)+400);
    console.log(height);
    $("body>.part2").css("top",height);
    $("body>.success-poup-box").css("top",height+500);
    $("body>.part2").removeClass("le-top");
    $("body>.success-poup-box").removeClass("le-msg-top");
});
$('.success-poup-box').click(function(e) {
    $(".success-poup-box").css("display","none");
});
$('[name~=grade]').css('color','#9e9e9e');
$('[name~=grade]').change(function() {
    var current = $('[name~=grade]').val();
    if (current != '') {
        $('[name~=grade]').css('color','#333333');
    } else {
        $('[name~=grade]').css('color','#9e9e9e');
    }
});
$('[name~=subject]').css('color','#9e9e9e');
$('[name~=subject]').change(function() {
    var current = $('[name~=subject]').val();
    if (current != '') {
        $('[name~=subject]').css('color','#333333');
    } else {
        $('[name~=subject]').css('color','#9e9e9e');
    }
});